package dnl.toolbox.lang;

import java.net.URL;

public class JWhich {

	/**
	 * Prints the absolute pathname of the class file containing the specified
	 * class name, as prescribed by the current classpath.
	 * 
	 * @param className
	 *            Name of the class.
	 */
	public static void whichClass(String className) {

		if (!className.startsWith("/")) {
			className = "/" + className;
		}
		className = className.replace('.', '/');
		className = className + ".class";

		java.net.URL classUrl = new JWhich().getClass().getResource(className);

		if (classUrl != null) {
			System.out.println("\nClass '" + className + "' found in \n'" + classUrl.getFile() + "'");
		} else {
			System.out.println("\nClass '" + className + "' not found in \n'" + System.getProperty("java.class.path")
					+ "'");
		}
	}

	public static void whichResource(String resourceName) {
		URL url = ClassLoader.getSystemResource(resourceName);
		if (url != null) {
			System.out.println("\nResource '" + resourceName + "' found in \n'" + url.getFile() + "'");
		} else {
			System.out.println("\nResource '" + resourceName + "' not found.'" + System.getProperty("java.class.path")
					+ "'");
		}
	}

}
